﻿using UnityEngine;
using System.Collections;


public class BloodBarKit :MonoBehaviour
{
    public MeshRenderer render;
    public Color col=Color.green;
    public float val=1f;
    //public float showTimer = 1f;
    
    public void Init()
    {
        val = 1f;
        col = Color.green;
    }

    void SetRenderValue()
    {
        render.materials[1].SetColor( @"_ColorTint", col );
        render.materials[1].SetFloat( @"_BloomValue", val*0.5f );
    }

    public void SetValue( float val)
    {
        this.val = Mathf.Clamp01( val );

        if(val >= 0.9f)
        {
            col = Color.green;
        }

        else if( val >= 0.6f )
        {
            float t=(val-0.6f)*3.333f;
            Color.Lerp( Color.yellow, Color.green, t );
        }

        else if( val >= 0.3f )
        {
            float t = (val-0.3f)*3.333f;
            col = Color.Lerp( Color.red, Color.yellow, t );
        }

        else
        {
            col = Color.red;
        }
        //showTimer = showTime;
        gameObject.SetActive(true);
        SetRenderValue();
    }

    //public void Show(float showTime = 50)
    //{
    //    showTimer = showTime;
    //    gameObject.SetActive(true);
    //}

    //public void Hide()
    //{
    //    gameObject.SetActive(false);
    //}

    //void Update()
    //{
    //    showTimer -= Time.deltaTime;
    //    if(showTimer <= 0)
    //    {
    //        gameObject.SetActive(false);
    //    }
    //}
}
